package com.appkubes.fintech.admin.application.risk.data.boole.utils;

/**
 * @Author: wuzhijian
 * @Date: 2019/12/25
 * @Description:
 * 驼峰、下划线互转
 */
public class CamelUnderLineUtil {
    private static final char UNDERLINE = '_';
    /***
     * @Author: wuzhijian
     * @Date: 2018/12/11 16:14
     * @param param
     * @Return java.lang.String
     * @Description:
     *  开头小写驼峰命名
     */
    public static String underlineToCamelLower(String param) {
        if (param == null || "".equals(param.trim())) {
            return "";
        }
        param = param.toLowerCase();
        int len = param.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = param.charAt(i);
            if (c == UNDERLINE) {
                if (++i < len) {
                    sb.append(Character.toUpperCase(param.charAt(i)));
                }
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    /**
     * @param param
     * @Author: wuzhijian
     * @Date: 2018/12/19 10:30
     * @Return java.lang.String 字符串
     * @Description: 驼峰命名转化成下划线
     */
    public static String CameCaseToUnderlineUpper(String param) {
        if (param == null || "".equals(param.trim())) {
            return "";
        }
        int len = param.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            if ((int) param.charAt(i) <= (int) 'Z' && (int) param.charAt(i) >= (int) 'A') {
                sb.append("_" + param.charAt(i));
            } else {
                sb.append(param.charAt(i));
            }
        }
        return sb.toString().toLowerCase();

    }

}
